
//2019年4月10日11:38:51 下载最新版的protobufJS 处理 .proto文件的方式

let file = protobuf.load("proto/copyInfo.proto",function (err,root) {
    if (err) {
        throw err;
    }
    let MsgCls=root.lookupType("CopyInfo");
    console.log("MsgCls",typeof(MsgCls));       
    let obj = {code:102,progress:80,desc:"这是副本"};
    //let message = MsgCls.fromObject(obj); //创建一个实例
    let message = MsgCls.create(obj); //创建一个实例 效果同 fromObject
    console.log("inst 11",message);
    let buffer = MsgCls.encode(message).finish();//把对象编码成二进制 buffer 固定得到一个 Unit8Array 
    console.log("buffer",buffer,buffer.length);
    
    let msgFromBuf=MsgCls.decode(buffer); //把二进制的buf转换成obj
    console.log("msgFromBuf",msgFromBuf);
    
    let object = MsgCls.toObject(msgFromBuf);
    console.log("object",object);
    
    
});
console.log(protobuf);
